package abtractTokens;

public class CellToken extends GeneralToken{
	/**
	 * An int value for the column that the cell is in.
	 */
	private int my_column;
	/**
	 * An int value for the row the cell is in
	 */
	private int my_row;
	/**
	 * Public constructor for CellToken
	 * @param the_value
	 */
	public CellToken(String the_value) {
		super(the_value);
		setType(TokenEnum.CELL);
		parseValue(the_value);
	}
	/**
	 * Parses the row and column info from the_value passed to the constructor.
	 * @param the_value The string value passed to the constructor.
	 */
	public void parseValue(String the_value){
		String temp_column = "";
		String temp_row = "";
		char temp_char;
		
		// separates row info from column info
		for( int i = the_value.length() - 1; i >= 0; i--) {
			temp_char = the_value.charAt(i);
			if (temp_char >= 48 && temp_char <= 57) { // temp_char is a digit
				temp_row = temp_row + temp_char;
			} else if (temp_char >= 65 && temp_char <= 90){ // temp_char is an upper-case letter
				temp_column = temp_column + temp_char;				
			} else if (temp_char >= 97 && temp_char <= 122){ // temp_char is a lower- case letter
				temp_char -= 32;
				temp_column = temp_column + temp_char;	
			} else {
				System.out.println("Char " + temp_char + " in " + the_value +
						" is not a letter or a digit");
			}
		}
		
		// Determines row value
		for (int i = temp_row.length() - 1; i >= 0; i--) {
			my_row = (my_row * 10) + (temp_row.charAt(i) - 48);			
		}

		// Determines column value
		for (int i = temp_column.length() - 1; i >= 0; i--) {
			my_column = (my_column * 26) + (temp_column.charAt(i) - 64);
		}
		
	}
	/**
	 * Returns the int value of the column that the CellToken represents.
	 * @return my_column.
	 */
	public int getColumn(){
		return my_column;
	}
/**
 * Returns the int value of the row the CellToken represents.
 * @param the_row my_row;
 */
	public int getRow(){
		return my_row;
	}
	
}
